<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl.WWWROOT_BACKEND; ?>/css/form.css"/>

<div class="wd-form">

<?php $form = $this->beginWidget('GxActiveForm', array(
	'id' => 'static-page-form',
	//'enableAjaxValidation' => true,
  'htmlOptions'=>array('enctype'=>'multipart/form-data'),
));
?>
	<fieldset>

	<p class="note">
		<?php echo Yii::t('app', 'Fields with'); ?> <span class="required">*</span> <?php echo Yii::t('app', 'are required'); ?>.
	</p>
	<?php echo $form->errorSummary($model); ?>

		<div class="wd-input">
		<?php echo $form->labelEx($model,'title'); ?>
		<?php echo $form->textField($model, 'title', array('maxlength' => 128)); ?>
		<?php echo $form->error($model,'title'); ?>
        <script type="text/javascript" language="javascript">
            jQuery(document).ready(function() {
                $('#Event_title').keyup(function(){
                    createAlias();
                });
                $('#Event_title').focusout(function(){
                    createAlias();
                });
								
								function createAlias()
								{
                    var value = $('#Event_title').val();
                    value = value.replace(/[áàảãạăắằẳẵặâấầẩẫậ]/ig, 'a');
                    value = value.replace(/[đ]/ig, 'd');
                    value = value.replace(/[éèẻẽẹêếềểễệ]/ig, 'e');
                    value = value.replace(/[íìỉĩị]/ig, 'i');
                    value = value.replace(/[óòỏõọôốồổỗộơớờởỡợ]/ig, 'o');
                    value = value.replace(/[úùủũụưứừửữự]/ig, 'u');
                    value = value.replace(/[ýỳỷỹỵ]/ig, 'y');
                    value = value.replace(/[^A-Za-z0-9\s_-]/ig, '');
                    value = value.replace(/\s/ig, '-');
                    value = value.toLowerCase();
                    $('#Event_alias').val(value);
								}
            });
        </script>
		</div><!-- wd-input -->
		<div class="wd-input">
		<?php echo $form->labelEx($model,'alias'); ?>
		<?php echo $form->textField($model, 'alias', array('maxlength' => 128)); ?>
		<?php echo $form->error($model,'alias'); ?>
		</div><!-- wd-input -->
		<div class="wd-input">
    <?php echo $form->labelEx($model,'image'); ?>
			<div class="image-form">
			<?php if (isset($model->image) && ($model->image != 'NULL')): ?>
				<?php if(file_exists(Yii::app()->createUrl('/').'wwwroot/upload_files/events/' . $model->image)): ?>
					<img src="<?php echo  Yii::app()->createUrl('/').'/wwwroot/upload_files/events/' . $model->image; ?>" width="100" height="70"/>
				<?php else : ?>
					<?php echo CHtml::image('/wwwroot/upload_files/events/no-image.png', 'Image', array(
								'width'		=>	'100',
								'height'	=>	'70'
					)); ?>
				<?php endif ?>
				<div class="clr"></div>
			<?php endif ?>
			<?php echo $form->fileField($model,'image'); ?>
			</div>
		<?php echo $form->error($model,'image'); ?>
		</div><!-- wd-input -->
		
		<div class="wd-input">
    <?php echo $form->labelEx($model,'background'); ?>
			<div class="image-form">
			<?php if (isset($model->background) && ($model->background != 'NULL')): ?>
				<?php if(file_exists(Yii::app()->createUrl('/').'wwwroot/upload_files/events/backgrounds/' . $model->background)): ?>
					<img src="<?php echo  Yii::app()->createUrl('/').'/wwwroot/upload_files/events/backgrounds/' . $model->background; ?>" width="100" height="70"/>
				<?php else : ?>
					<?php echo CHtml::image('/wwwroot/upload_files/events/no-image.png', 'Image', array(
								'width'		=>	'100',
								'height'	=>	'70'
					)); ?>
				<?php endif ?>
				<div class="clr"></div>
			<?php endif ?>
			<?php echo $form->fileField($model,'background'); ?>
			</div>
		<?php echo $form->error($model,'background'); ?>
		</div>
		
		<div class="wd-input">
			<?php echo $form->labelEx($model,'music'); ?>
			<div class="image-form">
			<?php if (isset($model->music) && ($model->music != 'NULL')): ?>
				<?php if(file_exists(Yii::app()->createUrl('/').'wwwroot/upload_files/events/musics/' . $model->music)): ?>
					<?php if(strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox')) { ?>
						<object data="<?php echo Yii::app()->createUrl('/').'/wwwroot/upload_files/events/musics/' . $model->music;?>" type="application/x-mplayer2" width="300px" height="50px">
							<param name="filename" value="<?php echo Yii::app()->createUrl('/').'/wwwroot/upload_files/events/musics/' . $model->music;?>">
							<param name="autostart" value="0">
						</object>
						<!-- >embed type="application/x-mplayer2" src="< ?php echo Yii::app()->createUrl('/').'/wwwroot/upload_files/galleries/musics/' . $model->music;?>" height="50px" width="300px" -->
					<?php } else { ?>
						<audio controls="controls">
							<source src="<?php echo Yii::app()->createUrl('/').'/wwwroot/upload_files/events/musics/' . $model->music;?>" type="audio/ogg" />
							<source src="<?php echo Yii::app()->createUrl('/').'/wwwroot/upload_files/events/musics/' . $model->music;?>" type="audio/mpeg" />
							Your browser does not support the audio element.
						</audio>
					<?php } ?>
				<?php else : ?>
					<?php echo CHtml::image('/wwwroot/upload_files/events/musics/no_music.jpg', 'Image', array(
								'width'		=>	'100',
								'height'	=>	'70'
					)); ?>
				<?php endif ?>
				<div class="clr"></div>
			<?php endif ?>
			<?php echo $form->fileField($model,'music'); ?>
			</div>
		<?php echo $form->error($model,'music'); ?>
		</div>
		
		<div class="wd-input">
		<?php echo $form->labelEx($model,'description'); ?>
		<?php echo $form->textArea($model, 'description'); ?>
		<?php echo $form->error($model,'description'); ?>
		</div><!-- wd-input -->
		<div class="wd-input">
		<?php echo $form->labelEx($model,'content'); ?>
		<?php //echo $form->textArea($model, 'content'); ?>
		<div class="ckeditor">
		<?php $this->widget('application.extensions.ckeditor.CKEditor', array(
			'model'=>$model,
			'attribute'=>'content',
			'language'=>'en',
			'editorTemplate'=>'advanced',
			'width'	=>	'620px',
			'height'	=>	'420px',
			'options'=>array(
				'filebrowserUploadUrl'=>$this->createUrl('upload'),
			),
			//'rows'=>10, 
			//'cols'=>30,
			'toolbar'=>array(
				array('Bold', 'Italic', 'Underline', 'Strike'),
				array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'),
				array('Format'),
				array( 'Font', 'FontSize', 'FontColor', 'TextColor'),
				'/',
				array('Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord' ),
				array('Image', 'Table', 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'),
				array('Subscript','Superscript'),
				array( 'Link', 'Unlink' ),
				array('Source'),
			)
			)); 
		?>
		</div>
		<?php echo $form->error($model,'content'); ?>
		</div><!-- wd-input -->
		<div class="wd-input">
		<?php echo $form->labelEx($model,'priority'); ?>
		<?php echo $form->textField($model, 'priority'); ?>
		<?php echo $form->error($model,'priority'); ?>
		</div><!-- wd-input -->
		<div class="wd-input">
		<?php echo $form->labelEx($model,'created'); ?>
		<?php echo $form->textField($model, 'created'); ?>
		<?php echo $form->error($model,'created'); ?>
		</div><!-- wd-input -->
		<div class="wd-input">
		<?php echo $form->labelEx($model,'modified'); ?>
		<?php echo $form->textField($model, 'modified'); ?>
		<?php echo $form->error($model,'modified'); ?>
		</div><!-- wd-input -->
		<div class="wd-input">
		<?php echo $form->labelEx($model,'is_published'); ?>
		<?php echo $form->checkBox($model, 'is_published'); ?>
		<?php echo $form->error($model,'is_published'); ?>
		</div><!-- wd-input -->
		<div class="wd-submit buttons">
		<?php echo GxHtml::submitButton(Yii::t('app', 'Save')); ?>
		</div>
	</fieldset>

<?php
$this->endWidget();
?>
</div><!-- form -->